using System;
using System.Collections;
using System.Collections.Generic;
using Base;
using OctoberStudio.Upgrades;
using UnityEngine;
using UnityEngine.UI;

public class MallPanel : MonoBehaviour
{
    [SerializeField] private Button backBtn;
    [SerializeField] Transform itemsParent;
    [SerializeField] GameObject itemPrefab;
    
    private UpgradeItem[] allData;
    void Start()
    {
        backBtn.onClick.AddListener(OnClosePanel);
        
        TextAsset jsonFile = Resources.Load<TextAsset>("Data/upgrades");
        UpgradeModel wrapper = JsonUtility.FromJson<UpgradeModel>(jsonFile.text);
        allData = wrapper.data;
        Debug.Log(allData.Length);
        
        foreach (Transform child in itemsParent)
        {
            Destroy(child.gameObject);
        }
        foreach (var itemData in allData)
        {
            MallItem item = Instantiate(itemPrefab, itemsParent).GetComponent<MallItem>();
            item.model = itemData;
        }
    }



    private void OnClosePanel()
    { 
        EventCenterManager.Instance.Dispatch(EventCommand.PanelShow,UIPanelShow.LobbyPanel);
        gameObject.SetActive(false);
    }

    private void OnDestroy()
    {
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
